'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	let status=0
	const collection = db.collection('User')
	const res = await collection.get()
	let users=res.data
	let user_info;
	if(event.type=="leader"){
		for(let i=0;i<users.length;i++){
			if(users[i].user_name==event.user_name){
				if(users[i].password==event.password){
					status=2
					user_info=users[i]
				}else{
					status=-1
				}
				break
			}
		}
	}else{
		for(let i=0;i<users.length;i++){
			if(users[i].user_name==event.user_name){
				status=2
				user_info=users[i]
				break
			}
		}
	}



	
	//返回数据给客户端
	return {
		"status":status,
		"user_info":user_info
	}
};
